
<!--主机-列表页面 -->
<section id="widget-grid" class="">
	<div class="row">
		<article class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
			<div class="widget-body">
				<!-- Dynamic Modal -->
				<div class="modal fade" id="addModal" tabindex="-1" role="dialog"
					aria-labelledby="addModalLabel" aria-hidden="true">
					<div class="modal-dialog">
						<div class="modal-content">
							<!-- content will be filled here from "ajax/modal-content/model-content-1.html" -->
						</div>
					</div>
				</div>
				<div class="modal fade" id="uploadModal" tabindex="-1" role="dialog"
					aria-labelledby="uploadModalLabel" aria-hidden="true">
					<div class="modal-dialog" style="margin-top: 10%; width: 500px;">
						<div class="modal-content">
							<!-- content will be filled here from "ajax/modal-content/model-content-1.html" -->
						</div>
					</div>
				</div>
				<div class="modal fade" id="mgmModal" tabindex="-1" role="dialog"
					aria-labelledby="mgmModalLabel" aria-hidden="true">
					<div class="modal-dialog" style="margin-top: 10%; width: 300px;">
						<div class="modal-content">
							<!-- content will be filled here from "ajax/modal-content/model-content-1.html" -->
						</div>
					</div>
				</div>
				<a href="javascript:void(0);" onclick="uploadExcel()"
					class="btn btn-success" id="uploadExcel">批量注册</a> <a
					href="javascript:void(0);" onclick="add_mainframe()"
					id="addmainframe" class="btn btn-success" data-toggle="modal"
					data-target="#addModal">注册</a> <a href="javascript:void(0);"
					class="btn btn-info" onclick="update_mainframe()"
					id="updatemainframe">编辑</a> <a href="javascript:void(0);"
					class="btn btn-info" onclick="in_mainframe()">入库</a> <a
					href="javascript:void(0);" class="btn btn-primary"
					onclick="start_mainframe()">启用</a> <a href="javascript:void(0);"
					class="btn btn-warning" onclick="stop_mainframe()">停用</a> <a
					href="javascript:void(0);" class="btn btn-danger"
					onclick="out_mainframe()" id="outmainframe">出库</a> <a
					href="javascript:void(0);" class="btn btn-info"
					onclick="hostDetail()" id="hostDetail">详情</a> <a
					href="javascript:void(0);" class="btn btn-primary"
					onclick="exportHost()">导出</a> <a href="javascript:void(0);"
					class="btn btn-warning" onclick="exportExcel()">模板下载</a> <a
					href="javascript:void(0);" class="btn btn-danger"
					onclick="delete_mainframe()">注销</a> <a href="javascript:void(0);"
					onclick="uploadMgm()" class="btn btn-success" id="uploadMgm">容器上限</a>
			</div>
			<p>&nbsp;</p>
		</article>
	</div>
	<div class="row">
		<div id="list-alert"></div>
	</div>
	<div class="row">
		<article class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
			<!-- Widget ID (each widget will need unique ID)-->

			<div id="pjqgrid"></div>
			<!-- end widget -->
			<table id="jqgrid"></table>

		</article>

	</div>
</section>
<div class="modal fade" id="taskModal" tabindex="-1" role="dialog"
	aria-labelledby="taskModalLabel" aria-hidden="true">
	<div class="modal-dialog" style="width: 100%;" id="dialogmodal">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-hidden="true">&times;</button>
				<h4 class="modal-title" id="taskModalLabel">任务状态提示</h4>
			</div>
			<div class="modal-body">
				<div class="table-responsive">
					<table class="table table-bordered">
						<thead>
							<tr>
								<th>所属者</th>
								<th>开始时间</th>
								<th>结束时间</th>
								<th>对象类型</th>
								<th>对象名称</th>
								<th>任务类型</th>
								<th>状态</th>
								<th width="30%">回执信息</th>
							</tr>
						</thead>
						<tbody id="mainframestate">
						</tbody>
					</table>

				</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭
				</button>
			</div>
		</div>
		<!-- /.modal-content -->
	</div>
	<!-- /.modal -->
</div>
<script>
	
    pageSetUp();
    var jqgrid_data;
    loadScript("js/plugin/jqgrid/grid.locale-en.min.js", function(){
    	loadScript("js/plugin/jqgrid/jquery.jqGrid.min.js", function(){
    		loadScript("js/create-jqgrid.js", function(){ 
	    		var siteid=getSession("siteId");
	    		sendGet("/upm_manager/v1.0/hosts?site="+siteid,createGrid_host_1,ListAlert,null);
	    		
    		});
    	});
    });
   
    // load related plugins
    var gridCluster=$("#jqgrid");
	function add_mainframe(){
    	$("#addmainframe").attr("href","views/resource/host/add.html");
	}
    function delete_mainframe(){
    	ListAlertClear();
       	var s = $("#jqgrid").jqGrid('getGridParam', 'selarrrow'); 
    	if(s.length==1){
    		 var hosts_id = $("#jqgrid").jqGrid('getRowData',s).id;
    	     ListConfirm('delete', hosts_id);
    	 }
    	 else{
    		 ListAlert("请勾选一行数据");
    	 }

    }
    function in_mainframe(){
    	ListAlertClear();
    	var s = $("#jqgrid").jqGrid('getGridParam', 'selarrrow'); 
    	if(s.length==1){
    		 var hosts_id = $("#jqgrid").jqGrid('getRowData',s).id;
    		 ListConfirm('in', hosts_id);
    	 }
    	 else{
    		 ListAlert("请勾选一行数据");
    	 }
    }
    function out_mainframe(){
    	ListAlertClear();
    	var s = $("#jqgrid").jqGrid('getGridParam', 'selarrrow'); 
    	if(s.length==1){
    		var id=$("#outmainframe");
    		id.attr("href","views/resource/host/out.html");
            id.attr("data-toggle","modal");
            id.attr("data-target","#addModal");
    	 }
    	 else{
    		 ListAlert("请勾选一行数据");
    		 id.removeAttr("data-toggle");
             id.removeAttr("data-target");
             id.removeAttr("href");
    	 }
    }
    function update_mainframe(){
    	ListAlertClear();
        s = gridCluster.jqGrid('getGridParam', 'selarrrow');
        var rowData = $("#jqgrid").jqGrid('getRowData',s);
        var id=$("#updatemainframe");
        if(s.length==1){
        	if(rowData.status == "input_no"){
	            id.attr("href","views/resource/host/update.html");
	            id.attr("data-toggle","modal");
	            id.attr("data-target","#addModal");
        	}else{
	            ListAlert("请在非入库状态下进行编辑!");
                id.removeAttr("data-toggle");
                id.removeAttr("data-target");
                id.removeAttr("href");
        	}
        }
        else{
        	ListAlert("请勾选一行数据");
            id.removeAttr("data-toggle");
            id.removeAttr("data-target");
            id.removeAttr("href");
        }
    }
    
    function hostDetail(){
    	ListAlertClear();
        s = gridCluster.jqGrid('getGridParam', 'selarrrow');
        var rowData = $("#jqgrid").jqGrid('getRowData',s);
        var id=$("#hostDetail");
        if(s.length==1){
	            id.attr("href","views/resource/host/detail.html");
	            id.attr("data-toggle","modal");
	            id.attr("data-target","#addModal");
        }
        else{
        	ListAlert("请勾选一行数据");
            id.removeAttr("data-toggle");
            id.removeAttr("data-target");
            id.removeAttr("href");
        }
    }
    
    function start_mainframe(){
    	ListAlertClear();
    	var s = $("#jqgrid").jqGrid('getGridParam', 'selarrrow'); 
    	if(s.length==1){
    		 var hosts_id = $("#jqgrid").jqGrid('getRowData',s).id;
    		 ListConfirm('start', hosts_id);
    	 }
    	 else{
    		 ListAlert("请勾选一行数据");
    	 }
    }
    function stop_mainframe(){
    	ListAlertClear();
    	var s = $("#jqgrid").jqGrid('getGridParam', 'selarrrow'); 
    	if(s.length==1){
    		 var hosts_id = $("#jqgrid").jqGrid('getRowData',s).id;
    		 ListConfirm('stop', hosts_id);
    	 }
    	 else{
    		 ListAlert("请勾选一行数据");
    	 }
    }
    
    function confirm(type, id){
    	switch(type){
    	case 'start':
    		sendPut("/upm_manager/v1.0/hosts/"+id+"/enable",showReturn,ListAlert,null,null);
    		break;
    	case 'stop':
   		    sendPut("/upm_manager/v1.0/hosts/"+id+"/disable",showReturn,ListAlert,null,null);
    		break;
    	case 'delete':
    		sendDelete("/upm_manager/v1.0/hosts/"+id, showReturn, ListAlert, null);
    		break;
    	case 'in':
    		sendPut("/upm_manager/v1.0/hosts/"+id+"/input",showReturn,ListAlert,"{}",null);
    		break;
    	default:
    	}
    }
    
    //下载
    function exportHost(){
    	 var $eleForm = $("<form method='post'></form>");
         $eleForm.attr("action","/upm_manager/v1.0/hosts/download?site="+getSession("siteId"));
         $(document.body).append($eleForm);
         $eleForm.submit();
    }
    
    //上传
    function uploadExcel(){
    	ListAlertClear();
    		var id=$("#uploadExcel");
    		id.attr("href","views/resource/host/upload.html");
            id.attr("data-toggle","modal");
            id.attr("data-target","#uploadModal");
    }
    
  	//容器上限
    function uploadMgm(){
    	ListAlertClear();
        s = gridCluster.jqGrid('getGridParam', 'selarrrow');
        var rowData = $("#jqgrid").jqGrid('getRowData',s);
        var id=$("#uploadMgm");
        if(s.length==1){
	            id.attr("href","views/resource/host/mgm.html");
	            id.attr("data-toggle","modal");
	            id.attr("data-target","#mgmModal");
        }
        else{
        	ListAlert("请勾选一行数据");
            id.removeAttr("data-toggle");
            id.removeAttr("data-target");
            id.removeAttr("href");
        }
    }
    
    function showReturn(){
    	sendGet("/upm_manager/v1.0/hosts?site="+getSession("siteId"),reloadGrid,ListAlert,null);
	}
    function reloadGrid(data){
    	ListAlertClear();
    	var jq_data=data['data'];  	
    	$("#jqgrid").clearGridData().setGridParam({data:jq_data}).trigger("reloadGrid");
    }
    
    $('#taskModal').on("show.bs.modal", function(e){
    	ListAlertClear();
    	$("#mainframestate").empty();
    	sendGet("/upm_manager/v1.0/tasks?obj_id="+$(e.relatedTarget).data('taskId'),createGrid_taskDetail,ListAlert,null);
    });
    
	clearInterval(flag);
	var flag = setInterval(showReturn, setTime);
</script>
